﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
//using TransferToExcel;

namespace BaMusaSoft.RPS.RPSServices.Reports
{
    public class SchedulesCustomersReport:IReport<SchedulesCustomersReportFields>
    {
        string excelTemplatePath;
        DataTable table;
        public SchedulesCustomersReport(string excelTemplatePath)
        {
            this.excelTemplatePath = excelTemplatePath;
            table = SchedulesCustomersReportFields.CreateDataTable();
        }
        public void Print()
        {
            try
            {
                //ExcelMail mail = new ExcelMail();
                //mail.SendToExcel(table, excelTemplatePath, true);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public void Build(IList<SchedulesCustomersReportFields> list)
        {
            if (list == null)
            {
                throw new ArgumentNullException("list");
            }

            try
            {
                foreach (var item in list)
                {
                    DataRow row = table.NewRow();
                    FillRow(item, row);
                    table.Rows.Add(row);
                    table.AcceptChanges();
                }

            }
            catch (Exception)
            {
                throw;
            }
        }
        #region "Helpers"
        private static void FillRow(SchedulesCustomersReportFields sourceItem, DataRow distRow)
        {
            distRow.SetField<string>("ScheduleId", sourceItem.ScheduleId);
            distRow.SetField<int>("CustomerId", sourceItem.CustomerId);
            distRow.SetField<string>("CustomerName", sourceItem.CustomerName);
            distRow.SetField<int>("AmountDue", sourceItem.AmountDue);
            distRow.SetField<string>("Mobile", sourceItem.Mobile);

            distRow.EndEdit();
        }
        #endregion

    }
}
